package game.entity;

import java.io.Serializable;

import engine.graphics.IUpdate;

public class EntityAttributes implements IUpdate, Serializable {

	private static final long serialVersionUID = 1L;
	
	private int maxHealth, health; 
	private int attack; 
	private int defense; 
	private int speed ; 
	
	public EntityAttributes(int health, int attack, int defense, int speed){
		setHealth(health);  setMaxHealth(health); 
		setAttack(attack); 
		setDefense(defense); 
		setSpeed(speed) ; 
	}
	
	public EntityAttributes(int health, int maxHealth, int attack, int defense, int speed){
		this(health, attack, defense, speed); 
		this.setMaxHealth(maxHealth);
	}
	
	public int getHealth() {
		return health;
	}

	public void setHealth(int health) {
		this.health = health;
	}

	private void setMaxHealth(int maxHealth){
		this.maxHealth = maxHealth ; 
	}
	
	public int getMaxHealth(){
		return this.maxHealth; 
	}
	
	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}

	public int getDefense() {
		return defense;
	}

	public void setDefense(int defense) {
		this.defense = defense;
	}
	
	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int movement) {
		this.speed = movement;
	}
	
	public void changeHealth(int value){
		health += value ; 
//		if(health>maxHealth)
//			setHealth(maxHealth);
	}

	private void changeMaxHealth(int value) {
		this.maxHealth += value ; 
//		if(maxHealth<health)
//			setHealth(maxHealth);
	}

	public void changeAttack(int value){
		attack += value ; 
	}
	
	public void changeDefense(int value) {
		defense += value ; 
	}
	
	public void changeSpeed(int value){
		speed += value ; 
	}
	
	public void changeAll(EntityAttributes values){
		this.changeAllAttributes(values);
	}
	
	private void changeAllAttributes(EntityAttributes values){
		changeHealth(values.getHealth());
		changeMaxHealth(values.getMaxHealth());
		changeAttack(values.getAttack()); 
		changeDefense(values.getDefense());
		changeSpeed(values.getSpeed());	
	}
		
	public EntityAttributes getInversion(){
		int h = - this.getHealth(); 
		int a = - this.getAttack(); 
		int d = - this.getDefense(); 
		int m = - this.getSpeed(); 
		int mh = - this.getMaxHealth();
		return new EntityAttributes(h, mh , a, d, m); 
	}
	
	public static EntityAttributes getDefaultAttributes(){
		return new EntityAttributes(10, 5, 5, 3); 
	}
	
	public String toString(){
		return "Health: "+health+"\nMax. Health: "+maxHealth+"\nAttack: "+attack+"\nDefense: "+defense+"\nSpeed: "+speed ; 
	}

	@Override
	public void update() {
		if(maxHealth<health)
			setHealth(maxHealth);
	}
	
}
